package com.example.qiniutest.image.tonken.service;

import com.example.qiniutest.image.config.QiniuConfig;
import com.qiniu.util.Auth;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TokenService {

    @Autowired
    private QiniuConfig qiniuConfig;

    private Auth auth;

    private String token;

    public String getToken(){
        if (token==null) getAuth();
        return  token;
    }

    public Auth getAuth(){
        if (auth==null){
            auth=Auth.create(qiniuConfig.accessKey,qiniuConfig.secretKey);
            token = auth.uploadToken(qiniuConfig.getBucket());
        }
        return auth;
    }
}
